<script setup lang="ts">
import { ref, computed } from 'vue'
import { DiyContractAgentConfig } from './data';
import applicationApi from '@/api/application'
import { onMounted } from 'vue';

const props = withDefaults(
  defineProps<{
    filteList?: any
  }>(),
  {
    filteList: {}
  }
)
const activeName = ref(0)

const renderStr = computed(() => {
  return DiyContractAgentConfig[2]
})

const applicationDetail = ref([
  {
    id: ''
  },
  {
    id: ''
  }
])
const applicationAvailable = ref(true)
const currentRecordList = ref([])
const currentChatId = ref(
  [
    { id: 'new'},
    { id: 'new'}
  ]
)
const document_list = ref<any>([
  {
    name:'【测试使用】建筑工程施工承包合同%20-2.docx',
    url:'/api/file/ea416eda-2375-11f0-8eea-0242ac120006',
    file_id: 'ea416eda-2375-11f0-8eea-0242ac120006'
  }
])
const meassage = ref('立场名称:施工方;补充审查重点:2222;')


async function submitItem({ appId, apiKey, token }: any, index: number) {
  // 获取token
  const appToken = await applicationApi.postAppAuthentication(token)
  // 获取应用信息
  const info = await applicationApi.getAppProfile1(ref(false), { 'AUTHORIZATION': appToken.data})
  console.log(info.data)
  applicationDetail.value[index] = info.data
  // 获取chatId
  const chatData = await applicationApi.getChatOtherOpen(appId, apiKey)
  console.log(chatData.data)
  currentChatId.value[index] = chatData.data
  const document_list = [
    {
      // name: routeQuery.value.name,
      // url: routeQuery.value.url,
      // file_id: routeQuery.value.file_id,
      name:'【测试使用】建筑工程施工承包合同%20-2.docx',
      url:'/api/file/ea416eda-2375-11f0-8eea-0242ac120006',
      file_id: 'ea416eda-2375-11f0-8eea-0242ac120006'
    }
  ]
  // const message = `立场名称:${formData.value.position};补充审查重点:${formData.value.supplement};`
  const meassage = `立场名称:施工方;补充审查重点:2222;`
}


async function init() {
  for (let index = 0; index < renderStr.value.length; index++) {
      const element: any = renderStr.value[index];
      await submitItem(element, index)
    }
}

onMounted(() => {
  init()
})


</script>

<template>
    <div class="diy-tabs-md">
      <el-tabs v-model="activeName" class="tabs">
          <el-tab-pane v-for="(items,index) in renderStr" :key="index" :label="items.name" :name="index">
            <div class="tabs">
                <AiChatDiy
                  v-model:applicationDetails="applicationDetail[index]"
                  :available="applicationAvailable"
                  type="ai-chat"
                  :appId="applicationDetail[index]?.id"
                  :record="currentRecordList"
                  :chatId="currentChatId[index].id"
                  :document_list="document_list"
                  :meassage="meassage"  
                />
            </div>
          </el-tab-pane>
      </el-tabs>
    </div>
  </template>

<style scoped lang="scss">
.diy-tabs-md{
  margin-top: -20px;
}
.tabs-item{
    background-color: #F5F5F5 ;
    margin-top: 12px;
    padding: 12px 16px;
    position: relative;
    border-radius: 4px;
    
}
.copy-all{
    display: flex;
    justify-content: end;
    background-color: #fff;
    padding: 12px 0;
}
:deep(.el-tabs__item) {
  color: #666;
  padding: 0 20px;
  height: 60px;
}
:deep(.el-tabs__item.is-active, .el-tabs__item:hover){
  color: var(--el-color-primary);
}
:deep(.el-tabs__header) {
  margin: 0;
}
</style>
